﻿#include <QQuickView>
#include "mainwindowhandlemessage.h"
// CTKPluginFramework includes
#include "ctkPluginContext.h"
#include "ctkPluginFrameworkLauncher.h"
#include "mainwindowservice.h"


MainWindowHandleMessage::MainWindowHandleMessage(QObject *parent)
    : QObject(parent)
{

}

void MainWindowHandleMessage::postCtkEvent(const QString event, const QVariant data, const QVariant extentionData)
{
    ctkPluginContext *context = ctkPluginFrameworkLauncher::getPluginContext();
    ctkServiceReference ref = context->getServiceReference<MainWindowService>();
    if (ref) {
        MainWindowService* service = context->getService<MainWindowService>(ref);
        if (service != nullptr) {
            service->postCtkEvent(event, data, extentionData);
            qInfo() << "event: " << event << "data: " << data << "extentionData: " <<extentionData;
            context->ungetService(ref);
        }
    } else {
       qFatal("MainWindowHandleMessage postCtkEvent failed.");
    }
}
